<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Set实践</title>
</head>
<body>
    <script>
        let arr = [1,2,3,4,5,4,5,2,3,7,6,4];
        // 拓展运算符把set集合变成数组
        let result = [...new Set(arr)];
        console.log(result);
        // 交集
        let arr2 = [4,5,6,5,6,8,9];
        // let result2 = [...new Set(arr)].filter(item => {
        //     let s2 = new Set(arr2);
        //     if(s2.has(item)){
        //         return true;
        //     }else{
        //         return false;
        //     }
        // });
        let result2 = [...new Set(arr)].filter(item => new Set(arr2).has(item));
        console.log(result2);

        // 并集
        let result3 = [...new Set([...arr,...arr2])];
        console.log(result3);

        //差集
        let diff = [...new Set(arr)].filter(item => !(new Set(arr2).has(item)));
        console.log(diff);
    </script>
</body>
</html>